#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = 500005;
struct io{
	char ibuf[1 << 25],*s;
	io(){
		fread(s=ibuf,1,1<<25,stdin);
	}
	inline int read(){
		register int u=0,v=1;
		while(*s<48)
			v=*s++^45?1:-1;
		while(*s>32)
			u=u*10+*s++-48;
			return u*v;
	}
}ip;
#define read ip.read

int head[maxn],n,m,s,edge_num;
int d[maxn],p[maxn][30];
struct node{
	int next,to;
}edge[maxn*2];

void add_edge(int from,int to){
	edge_num++;
	edge[edge_num].next=head[from];
	edge[edge_num].to=to;
	head[from]=edge_num;
}

void dfs(int u){
	for(int i=head[u];i!=0;i=edge[i].next){
		int to=edge[i].to;
		if(to==p[u][0])continue;
		d[to]=d[u]+1;
		p[to][0]=u;
		dfs(to);
	}
}

void init(){
	for(int j=1;(1<<j)<=n;j++){
		for(int i=1;i<=n;i++){
			p[i][j]=p[p[i][j-1]][j-1];
		}
	}
}

int lca(int a,int b){
	if(d[a]>d[b])swap(a,b);
	int f=d[b]-d[a];
	for(int i=0;(1<<i)<=f;i++){
		if(1<<i &f)b=p[b][i];
	}
	if(a==b)return a;
	else{
		for(int i=(int)log2(n);i>=0;i--){
			if(p[a][i]!=p[b][i]){
				a=p[a][i];b=p[b][i];
			}
		}
	}
	return p[a][0];
}

int main(){
	n=read();
	m=read();
	s=read();
	int a,b;
	for(int i=1;i<=n-1;i++){
		a=read();b=read();
		add_edge(a,b);
		add_edge(b,a);
	}	
	for(int i=1;i<=n;i++)p[i][0]=i;
	d[1]=1;
	dfs(s);
	init();
	for(int i=1;i<=m;i++){
		a=read();b=read();
		cout<<lca(a,b)<<endl;
	} 
	return 0;
}
